package com.bdqn.service;

import com.bdqn.common.MD5Util;
import com.bdqn.mapper.AccountMapper;
import com.bdqn.pojo.Account;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AccountServiceImpl implements AccountService{

    @Resource
    private AccountMapper accountMapper;

    /**
     * 根据用户名获取客户信息
     * @param name
     * @return
     */
    @Override
    public Account findByName(String name) {
        return accountMapper.findByName(name);
    }


    /**
     * 客户信息搜索查询
     * @param queryMap
     * @return
     */
    @Override
    public List<Account> findList(Map<String, Object> queryMap) {
        return accountMapper.findList(queryMap);
    }

    /**
     * 模糊搜索总条数
     * @param queryMap
     * @return
     */
    @Override
    public Integer getTotal(Map<String, Object> queryMap) {
        return accountMapper.getTotal(queryMap);
    }

    /**
     * 获取单个客户信息
     * @param id
     * @return
     */
    @Override
    public Account find(Long id) {
        return null;
    }

    /**
     * 获取所有客户信息
     * @return
     */
    @Override
    public List<Account> findAll() {
        return accountMapper.findAll();
    }


    /**
     * 客户插入操作
     * @param account
     * @return
     */
    @Override
    public int add(Account account) {
        account.setPassword(MD5Util.md5Password(account.getPassword()));// 密码加密
        return accountMapper.add(account);
    }


    /**
     *  客户编辑操作
     * @param account
     * @return
     */
    @Override
    public int edit(Account account) {
        return accountMapper.edit(account);
    }

    @Override
    public Account account(Long id) {
        return accountMapper.account(id);
    }

    @Override
    public int update(Long id) {
        return accountMapper.update(id);
    }
}
